OpenRoads Designer CONNECT Edition SDK Help

Corridor reporter

Description

  • This is custom class for generating data related to corridor.

  • It generates data of all corridor components including name, feature name, slope area, volume etc.

Remarks

  • This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.

  • This code is simplified and does not include report generation code, but user can get it under ManagedSDKExample ->Examples ->CorridorReporter.

Source Code


//Required References
using System.Collections.Generic;
using Bentley.DgnPlatformNET.Elements;
using Bentley.GeometryNET;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK;
using Bentley.CifNET.Geometry;
using Bentley.DgnPlatformNET;
using Bentley.CifNET.Formatting;

namespace ExampleSnippetAddIn.Examples
{

    class CorridorReporter
    {
        internal static DgnModel m_activeModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
       
        /*------------------------------------------------------------------------------------**/
        /* Reads corridors and creates data for report generation.
        /*--------------+---------------+---------------+---------------+---------------+------*/
        internal void ReportAllCorridors()
        {
            ConsensusConnection sdkCon = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
            if (sdkCon == null)
                return;

            GeometricModel geomModel = sdkCon.GetActiveGeometricModel();
            if (geomModel == null)
                return;

            foreach (Corridor cor in geomModel.Corridors)
            {
                foreach (CorridorSurface cs in cor.CorridorSurfaces)
                {
                    if (cs.Type.Contains("Hidden"))
                        continue;
                    CorridorMeshComponent(cs);
                }
            }
        }

        private void CorridorMeshComponent(CorridorSurface cs)
        {

            Dictionary<string, string> properties = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(cs.Name))
                properties.Add("Name", cs.Name);
            if (!string.IsNullOrEmpty(cs.FeatureName))
            {
                properties.Add("Feature Name", cs.FeatureName);
                MeshHeaderElement mesh = (MeshHeaderElement)cs.Element;
                PolyfaceHeader polyface = mesh.GetMeshData();
                MeshElement meshEle = new MeshElement(polyface);
                double volume = meshEle.PolyfaceVolume;
                double area = meshEle.SlopedArea;
                // Only shows the area of upward facing meshes (the top areas)
                properties.Add("Slope Area", FormatArea(area));
                properties.Add("Volume", FormatVolume(volume));
                properties.Add("Top Mesh", cs.IsTopMesh.ToString());
                properties.Add("Bottom Mesh", cs.IsBottomMesh.ToString());
            }
        }

        public static string FormatArea(double value)
        {
            ModelInfo info = m_activeModel.GetModelInfo();
            double metersPerUor = 1.0 / info.UorPerMeter;
            double defaultUnitsToSquareMeters = (metersPerUor * metersPerUor);
            return FormattingProvidersManager.Instance[ECAreaTypeConverter.FormatGuid].FormatValue(value * defaultUnitsToSquareMeters, 0);
        }

        public static string FormatVolume(double value)
        {
            ModelInfo info = m_activeModel.GetModelInfo();
            double metersPerUor = 1.0 / info.UorPerMeter;
            double defaultUnitsToCubicMeters = (metersPerUor * metersPerUor * metersPerUor);
            return FormattingProvidersManager.Instance[ECVolumeTypeConverter.FormatGuid].FormatValue(value * defaultUnitsToCubicMeters, 0);
        }
    }
}